// OUTDOOR SECTION SCRIPT
//    Section: X = 0, Y = 0

// This is the special encounter script for this town.
// The states INIT_STATE and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

//
// flags:
// 200, 0   = farmhouse in the north
// 200, 1-2 = crevasse message flags
// 200, 3   = shown way through crevasse
// 200, 4   = after winning, rmv enc flag check
//

beginoutdoorscript;

variables;

short choice, fin;

body;

beginstate INIT_STATE;
// This state called whenever this section is loaded into memory.
break;

beginstate START_STATE;
	// one time check after winning to remove outdoor encounters that may exist
	if ((get_flag(50, 1) > 0) && (get_flag(200, 4) == FALSE)) {
		set_flag(200, 4, TRUE);
		if (outdoor_enc_exists(50, 1) == TRUE) {
			eliminate_outdoor_enc(50, 1);
		}
	}
break;

beginstate 10;
	block_entry(1);
	fin = get_flag(50, 0);
	reset_dialog();
	add_dialog_str(0, "Ahead of you is the path leading away from the wilderness.", 0);
	if (fin == FALSE)
		add_dialog_str(1, "You haven't completed the quest to restore the staff yet.", 0);
	else
		add_dialog_str(1, "You've restored the staff and defeated the archmage Zanta.", 0);
	add_dialog_choice(0, "Stay here.");
	add_dialog_choice(1, "Leave for other adventures elsewhere.");
	choice = run_dialog(0);
	if (choice == 2) {
		reset_dialog();
		if (fin == TRUE) {
			add_dialog_str(0, "You walk with a light-hearted step, knowing your destiny was fulfilled.", 0);
			add_dialog_str(1, "You pause and look back into The Wilderness, then turn and walk away to what faces you next.", 0);
			add_dialog_str(2, "You leave behind The Wilderness, once more safe and at peace.", 0);
		}
		else {
			add_dialog_str(0, "Your destiny is unfulfilled and The Wilderness still cries out.", 0);
			if (get_flag(50, 3) > 0) {
				add_dialog_str(1, "You care not, leaving with the restored Staff of Turin in your hands.", 0);
				add_dialog_str(2, "You fleetingly feel an angry presence that will one day will give chase and a day of reckoning.", 0);
			}
			else {
				add_dialog_str(1, "You were not able to even restore the Staff of Turin.", 0);
				add_dialog_str(2, "The cries and groans of the people of The Wilderness echo in your ears.", 0);
			}
			add_dialog_str(3, "You move a little faster, leaving The Wilderness behind you.", 0);
		}
		add_dialog_choice(0, "Ok");
		choice = run_dialog(FALSE);
		end_scenario(fin);
	}
break;

beginstate 11;
	if (get_flag(200, 0) == FALSE) {
		set_flag(200, 0, TRUE);
		message_dialog("The farmhouse is locked up since no one is home.",
			"The farmer is probably doing something useful elsewhere, staying out of the way of the bad element.");
	}
break;

beginstate 12;
	if ((get_flag(51, 10) == TRUE) && (char_ok(4) == TRUE)) {
		if (get_flag(200, 1) == FALSE) {
			set_flag(200, 1, TRUE);
			set_flag(200, 2, TRUE); // just in case not run into before Charlie...
			set_flag(200, 3, TRUE);
			reset_dialog();
			add_dialog_str(0, "As you get to a crevasse in the cliff face, Charlie says 'We're here.'", 0);
			add_dialog_str(1, "He proceeds to show you how to climb up the crevasse to the path beyond.", 0);
			add_dialog_str(2, "Charlie waves bye, takes his leave of the party and heads back for Tangramayne.", 0);
			add_dialog_choice(0, "Ok");
			choice = run_dialog(FALSE);
			if (remove_char_from_party(600) == TRUE) {
				print_str_color("Charlie leaves.", 2);
			}
			else {
				print_str_color("Somehow, a bug of fate leaves Charlie in the party.", 2);
			}
		}
	}
	else {
		if (get_flag(200, 2) == FALSE) {
			set_flag(200, 2, TRUE);
			message_dialog("You hear wind whistling down through the crevasse leading back into the cliff wall.",
				"You can't quite make out how to climb through it, though you can see a path leading further up.");
		}
	}
break;

beginstate 13;
	if (get_flag(200, 3) == FALSE) {
		block_entry(TRUE);
	}
	else {
		block_entry(FALSE);
	}
break;
